package com.xc.hotelmgr.consumermq.controller;

import com.xc.hotelmgr.consumermq.service.mq.MQSetService;
import com.xc.hotelmgr.consumermq.utils.ComResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("consumer")
@RequiredArgsConstructor
@Slf4j
public class ConsumerController {

    private final MQSetService mqSetService;

    /**
     * 容器添加队列
     * @param params
     * @return
     */
    @PostMapping("add")
    public ComResult add(@RequestBody Map<String, Object> params) {
        String appKey = (String) params.get("appKey");
        try {
            mqSetService.add(appKey);
        }catch (RuntimeException e) {
            log.error(e.getMessage());
            return new ComResult(-1, "消费者添加失败");
        }
        return new ComResult(0, "消费者添加成功");
    }

    /**
     * 容器消费者更新
     * @param params
     * @return
     */
    @PostMapping("update")
    public ComResult update(@RequestBody Map<String, Object> params) {
        try {
            mqSetService.update(params);
        }catch (RuntimeException e) {
            return new ComResult(-1, "消费者数量更新失败");
        }
        return new ComResult(0, "消费者数量更新成功");
    }
}
